home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Math / Matvec.sam < prev    next >
Text File  |  1997-03-08  |  8KB  |  160 lines

  1. (* 
  2.  
  3. The matrix and vector classes were originally developed by S.
  4. Omohundro.  Later, however, Matt Kennel put a tremendous effort into
  5. defining new abstractions and links into the BLAS libraries.  These
  6. are his notes on the fundamental numerical matrix classes for Sather.
  7.  
  8. First issue to clarify: what is the difference between a "matrix" and
  9. a "two-dimensional array"?
  10.  
  11. A: A matrix is a finite-dimensional linear operator over a given
  12. coordinate system (the vector space).  As such it pretty much only
  13. makes sense to have matrices whose elements are ring elements, that
  14. is, can add, subtract and multiply, have additive and and
  15. multiplicative identities, as well as additive inverses.
  16.  
  17.  At this stage, I'm going to require in addition that the matrix
  18. elements also be _field elements_, requiring that they have
  19. multiplicative inverses and hence division.  The only fields that I
  20. can really see right now being relevant are the real and complex
  21. numbers, each implemented as single precision or double precision
  22. floating point.  Maybe quaternions would be useful for somebody, but
  23. one must keep in mind that quaternions are not Abelian (commutative)
  24. and so care would have to be taken to define proper order of
  25. operations.
  26.  
  27.  Matrices are often _implemented_ in terms of two-dimensional arrays
  28. of numbers, but this is not fundamental.  Indeed in realistic
  29. numerical problems it may make sense to implement matrices in terms of
  30. only that small subset of non-zero elements {sparse matrices} or,
  31. perhaps as a combination of principal components and significant
  32. eigenvectors or whatever.  In linear algebra computations there are
  33. often "factorizations" of matrices: M -> L*U.  A structure consisting
  34. of "L*U" is a good representation for a matrix just as well as a dense
  35. 2-d array of numbers.
  36.  
  37.  Still, the initial goal for the matrix classes is to provide convenient
  38. access to standard computational routines for single and double precision
  39. real and complex matrices.
  40.  
  41.  The Basic matrix classes only include routines for generic dense
  42. rectangular matrices, and no sophisticated linear algebra algorithms.
  43.     
  44.  By contrast the Fancy matrix classes will include linear algebra
  45. computations such as solving systems of linear equations,
  46. eigenproblems, and various kinds of matrix decompositions on dense and
  47. special sparse matrices.
  48.  
  49.  The Basic matrix class will only assume and require the presence of
  50. BLAS and not LAPACK.  Furthermore, it will NOT provide all of the BLAS
  51. functionality, just those parts relevant to operations on general
  52. dense matrices and vectors.  The Fancy matrix classes will extend the
  53. basic matrix classes by adding most of of the BLAS functionality and
  54. some reasonable subset of LAPACK.  The extent of this depends on how
  55. much gets done by me and other volunteers.
  56.  
  57.  The Basic matrix classes are, in fact, implemented as a
  58. two-dimensional array of numbers.  We choose the *column-major* layout
  59. in memory, following Fortran convention, so as to aid interfacing with
  60. the huge corpus of Fortran numerical routines.  Most other langauges,
  61. e.g. C use row-major arrays by default.  The rather feeble
  62. ``built-in'' 2-d arrays in C++ add nothing beyond those in C. C++
  63. matrix classes use a wide variety of representations, but no matrix
  64. class is yet standard.
  65.  
  66.  The goal of the Sather Basic Matrix Class is to provide a standard
  67. single matrix class design as good as the best C++ classes, with a
  68. standard high-performance implementation as good as the best C++
  69. classes.
  70.  
  71.  Any successful program library requires a thoughtful design.  It
  72. should provide enough diversity in functionality to support a wide
  73. range of applications, and yet the library should be as simple as
  74. possible.  Better to have a few key mechanisms instead of a profusion
  75. of similar, but not identical mechanisms.  Finally, it should provide
  76. maximum performance.
  77.  
  78.  The tension between these three is eternal and fundamental.  Its
  79. resolution requires creativity and experience.
  80.  
  81.  Fortunately, the computational world has extensive experience with
  82. linear algebra, and thus the difficult intellectual classifications
  83. have already been done.
  84.  
  85.  In particular, the Basic Linear Algebra Subroutines (BLAS) are the
  86. standard "core" algorithms for contemporary "standard" numerical
  87. subroutines.
  88.  
  89.  In particular, the famous LINPACK and EISPACK, now superseded by
  90. LAPACK, use BLAS routines.
  91.  
  92.  BLAS routines sometimes come written in assembly expertly tuned for
  93. high performance on various platforms.  Even without this, there are
  94. free C and Fortran sources for the BLAS.  {LAPACK and BLAS are
  95. available for download on the Internet from NETLIB, the de facto
  96. standard repository for computational software.  You can use FTP or
  97. the WWW and connect to "netlib.att.com" or "netlib.ornl.gov".}
  98.  
  99.  Thus the standard implementation of Sather's matrix classes will rely
  100. on BLAS routines to for the computational gruntwork.  The fuller
  101. matrix classes will use BLAS and LAPACK to provide easy-to-use
  102. interfaces to a variety of sophisticated high-performance numerical
  103. algorithms.
  104.  
  105.  Out of the three factors mentioned above, the BLAS routines have been
  106. developed mostly for performance.  Their algorithmic interfaces to the
  107. human programmer are not particularly friendly.  The Sather Basic
  108. matrix classes are intended to provide a convenient front-end with
  109. idiomatic Sather functionality to traditional Fortran routines without
  110. substantially sacrificing performance.  In choosing member routines, I
  111. put a higher priority on providing many explicit variations of
  112. operations for the sake of having the least overhead instead of
  113. accepting some run-time penalty in favor of having a tighter and
  114. smaller class interface.
  115.  
  116.  This is similar to the goal of the LAPACK++ library for C++.  I think
  117. this is the best C++ matrix class library, and I will keep it in mind
  118. while designing the Sather library, though I do not intend to copy it
  119. slavishly.  In particular LAPACK++ pretty much requires LAPACK as well
  120. as BLAS; I hope to have a basic subset which does not LAPACK to
  121. compile.  The LAPACK++ library accesses individual elements through
  122. double indirection; its matrix classes contain a pointer to
  123. dynamically allocated raw storage.  That allows 'matrix references'
  124. that denote subsets of existing matrices (3rd through 5th row, 2nd
  125. through 9th column of A) to be the same class as the matrix class
  126. itself simplifying the interface at some performance cost.  I choose
  127. not to pursue this design for the sake of performance.  As is natural
  128. for Sather, the heap storage for the matrix will be contained "in" the
  129. object itself via an inheritance path to AREF{T}.  At some point
  130. 'matrix reference' classes may be written if there is a need.
  131.  
  132.  The Sather compiler itself has optimization technology capable of
  133. making naive executable code for numerical kernels that is much faster
  134. than naive C++ and C, though handtuned C can achieve somewhat better
  135. results.  
  136.  
  137.  However, for today's microprocessors, kernels hand tuned for a
  138. particular architecture and cache can perform far better than even
  139. fairly careful, portable C. Most users will be better served by front
  140. ends to those fast and reliable algorithms in BLAS and LAPACK rather
  141. than new development in Sather.
  142.  
  143.  Other sorts of algorithms, e.g. minimizations, ODE integrations,
  144. genetic algorithms and the like would benefit more from the modern
  145. data structuring and object-orientation facilities of Sather, and hence
  146. native rewrites would be more rewarding.  I hope somebody tries to
  147. work on these, as I don't have the time or expertise.
  148.  
  149. *)
  150.  
  151. abs_mat.sa  -has abs_mat.sa $MAT
  152. mat.sa  -has mat.sa MAT NUMERIC_MAT
  153. matd.sa -has matd.sa MATD
  154. matcpx.sa -has matcpx.sa MATCPX MATCPXD
  155. abs_vec.sa -has abs_vec.sa $VEC
  156. vec.sa  -has vec.sa VEC VEC_LENGTH_MIXIN 
  157. vecd.sa -has vecd.sa VECD
  158. veccpx.sa -has veccpx.sa VECCPX_LENGTH_MIXIN VECCPX VECCPXD
  159. test/matvec.sa -has test/matvec.sa TEST_MATVEC
  160.